import { message } from 'antd';
import { history } from 'umi';
import { addItem } from '@/services/item/item';

const Model = {
  namespace: 'addItem',
  state: {
    status: false,
  },
  effects: {
    *submit({ payload }, { call, put }) {
      const response = yield call(addItem, payload);
      if (response.success === true) {
        message.success(`上传成功！`);
        yield put({
          type: 'saveStatus',
          payload: true,
        });
        history.push('/item/myItemList');
      } else {
        message.error(`上传失败！,${response.message}`);
      }
    },
  },
  reducers: {
    saveStatus(state, { payload }) {
      return { ...state, status: payload };
    },
  },
};
export default Model;
